<?php
/**
 * //w/w/w.s/h/u/o/t//u/p/u c/o/m  说/图/谱/源/码/分/享
 */
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/21 0021
 * Time: 上午 9:16
 */
defined("IN_IA")or exit("Access Denied");
checklogin();  //验证是否登录
global $_W,$_GPC;
$uniacid=$_W['uniacid'];
$op=$_GPC['op'] ? $_GPC['op'] : "integral_shop";
if($op=='integral_shop'){
    $condition=array();
    if(!empty($_GPC['goods_name'])){
        $goods_name=$_GPC['goods_name'];
        $condition['goods_name LIKE']='%'.$goods_name.'%';
    }
    $condition['uniacid']=$uniacid;

    $all=pdo_getall('cqkundian_farm_integral_goods',$condition);
    $count=count($all);
    $pageSize=10;
    $pageIndex=$_GPC['page'] ? intval($_GPC['page']) : $_GPC['page'];
    $pager=pagination($count,$pageIndex,$pageSize);
    $list=pdo_getall('cqkundian_farm_integral_goods',$condition,'','','rank asc',array($pageIndex,$pageSize));
    for($i=0;$i<count($list);$i++){
        $typeData=pdo_get('cqkundian_farm_integral_goods_type',array('id'=>$list[$i]['type_id'],'uniacid'=>$uniacid));
        $list[$i]['type_name']=$typeData['type_name'];
    }
    include $this->template("web/integralShop/goods_list");
}
//添加商品信息
if($op=='edit'){
    //商品分类信息
    $goodsType=pdo_getall('cqkundian_farm_integral_goods_type',array('uniacid'=>$uniacid,'status'=>1));
    include $this->template("web/integralShop/update");
}

//保存商品信息
if($op=='saveModel'){
    $url=url('site/entry/integralShop', array('m' => 'kundian_farm','op'=>'integral_shop'));
    $goods_slide=$_GPC['goods_slide'];
    for($i=0;$i<count($goods_slide);$i++){
        $goods_slide[$i]=tomedia($goods_slide[$i]);
    }
    $insertData=array(
        'goods_name'=>trim($_GPC['goods_name']),
        'type_id'=>$_GPC['type_id'],
        'price'=>trim($_GPC['price']),
        'old_price'=>trim($_GPC['old_price']),
        'sale_count'=>trim($_GPC['sale_count']),
        'count'=>trim($_GPC['count']),
        'cover'=>tomedia($_GPC['cover']),
        'is_put_away'=>$_GPC['is_put_away'],
        'is_recommend'=>$_GPC['is_recommend'],
        'rank'=>$_GPC['rank'],
        'is_open_sku'=>$_GPC['is_open_sku'],
        'goods_slide'=>serialize($goods_slide),
        'uniacid'=>$uniacid,
        'goods_desc'=>$_GPC['goods_desc'],
        'send_price'=>$_GPC['send_price'],
    );

    //插入商品信息
    $goodsRes=pdo_insert('cqkundian_farm_integral_goods',$insertData);
    $goods_id=pdo_insertid();  //商品id

    if($_GPC['is_open_sku']!=1){  //没有规格
        if($goodsRes){
            message("操作成功",$url);
        }else{
            message("操作失败");
        }
    }else{  //有规格

        $sku_name=$_GPC['sku_name'];
        $item=$_GPC['item'];
        $spec_src=$_GPC['spec_src'];
        $specItem=$_GPC['specItem'];  //规格项
        $itemDataList=array();
        if(count($specItem)>1){
            $merge=array_merge_recursive($item,$sku_name);
            foreach ($merge as $k=>$v) {
                $itemDataList[]=array(
                    'price'=>$v['price'],
                    'count'=>$v['count'],
                    'sku_name'=>$k,
                    'spec_num'=>$v['goods_num'],
                );
            }
        }else{
            foreach ($item as $k => $v) {
                $itemDataList[]=array(
                    'price'=>$v['price'],
                    'count'=>$v['count'],
                    'sku_name'=>$k,
                    'spec_num'=>$v['goods_num'],
                );
            }
        }
        $res_spec=0;
        for($i=0;$i<count($itemDataList);$i++){
            $itemDataList[$i]['spec_src']=tomedia($spec_src[$i]);
            $itemDataList[$i]['goods_id']=$goods_id;
            $itemDataList[$i]['uniacid']=$uniacid;
            $res_spec+=pdo_insert('cqkundian_farm_integral_goods_spec',$itemDataList[$i]);  //插入商品规格
        }
        //修改规格项的goods_id
        $res_spec_item=0;
        for($i=0;$i<count($specItem);$i++){
            $res_spec_item+=pdo_update('cqkundian_farm_integral_spec',array('goods_id'=>$goods_id),array('id'=>$specItem[$i],'uniacid'=>$uniacid));
        }
        if($res_spec && $res_spec_item){
            message("操作成功",$url);
        }else{
            message("操作失败");
        }
    }

    die;
}


//修改商品信息时初始化获取规格项
if($op=='getEditSpecItem'){
    $request=array();
    $goods_id=$_GPC['goods_id'];    //商品id
    //根据商品获取规格值
    $editSpecVal=pdo_getall('cqkundian_farm_integral_spec',array('uniacid'=>$uniacid,'goods_id'=>$goods_id));
    //根据规格项id获取规格值
    $spec_id=array();
    for($i=0;$i<count($editSpecVal);$i++){
        $specItem=pdo_getall('cqkundian_farm_integral_spec_value',array('uniacid'=>$uniacid,'spec_id'=>$editSpecVal[$i]['id']));
        $editSpecVal[$i]['specValue']=$specItem;
        $spec_id[]=$editSpecVal[$i]['id'];
    }
    $returnStr=getSpecSku($spec_id,$uniacid);

    $newSkuSpec=$returnStr['newSkuSpec'];
    $goodsSpecVal=array();
    for($j=1;$j<=count($newSkuSpec);$j++){
        $goodsSpecVal[$j-1]=pdo_get('cqkundian_farm_integral_goods_spec',array('sku_name'=>$newSkuSpec[$j],'goods_id'=>$goods_id,'uniacid'=>$uniacid));
    }
    $request['specVal']=$editSpecVal;
    $request['specItem']= $returnStr['specItem'];
    $request['newSkuSpec']=$returnStr['newSkuSpec'];
    $request['skuSpec']=$returnStr['skuSpec'];
    $request['goodsSpecVal']=$goodsSpecVal;
    echo json_encode($request);die;
}


//修改商品信息
if($op=='goods_edit'){
    $typeData=pdo_getall('cqkundian_farm_integral_goods_type',array('uniacid'=>$uniacid));

    $id=$_GPC['id'];
    $list=pdo_get('cqkundian_farm_integral_goods',array('id'=>$id,'uniacid'=>$uniacid));
    $list['goods_slide']=unserialize($list['goods_slide']);  //反序列化商品轮播图
    $specData=pdo_getall('cqkundian_farm_integral_goods_spec',array('goods_id'=>$id,'uniacid'=>$uniacid));
    $spec_src=array();
    for($i=0;$i<count($specData);$i++){
        $spec_src[]=$specData[$i]['spec_src'];
    }
    include $this->template('web/integralShop/goods_update');
}

//保存修改信息
if($op=='goods_edit_save'){
    $url=url('site/entry/integralShop', array('m' => 'kundian_farm','op'=>'integral_shop'));
    $goods_id=$_GPC['id'];
    $goods_slide=$_GPC['goods_slide'];
    for($i=0;$i<count($goods_slide);$i++){
        $goods_slide[$i]=tomedia($goods_slide[$i]);
    }
    $insertData=array(
        'goods_name'=>trim($_GPC['goods_name']),
        'type_id'=>$_GPC['type_id'],
        'price'=>trim($_GPC['price']),
        'old_price'=>trim($_GPC['old_price']),
        'sale_count'=>trim($_GPC['sale_count']),
        'count'=>trim($_GPC['count']),
        'cover'=>tomedia($_GPC['cover']),
        'is_put_away'=>$_GPC['is_put_away'],
        'is_recommend'=>$_GPC['is_recommend'],
        'rank'=>$_GPC['rank'],
        'is_open_sku'=>$_GPC['is_open_sku'],
        'goods_slide'=>serialize($goods_slide),
        'uniacid'=>$uniacid,
        'goods_desc'=>$_GPC['goods_desc'],
        'send_price'=>$_GPC['send_price'],
    );
    //修改商品信息
    $goods_update_res=pdo_update('cqkundian_farm_integral_goods',$insertData,array('id'=>$goods_id,'uniacid'=>$uniacid));
    //判断是否开启规格项
    if($_GPC['is_open_sku']==1){  //开启
        $sku_name=$_GPC['sku_name'];
        $item=$_GPC['item'];
        $spec_src=$_GPC['spec_src'];
        $specItem=$_GPC['specItem'];  //规格项
        $itemDataList=array();
        if(count($specItem)>1){
            $merge=array_merge_recursive($item,$sku_name);
            foreach ($merge as $k=>$v) {
                $itemDataList[]=array(
                    'price'=>$v['price'],
                    'count'=>$v['count'],
                    'sku_name'=>$k,
                    'spec_num'=>$v['goods_num'],
                );
            }
        }else{
            foreach ($item as $k => $v) {
                $itemDataList[]=array(
                    'price'=>$v['price'],
                    'count'=>$v['count'],
                    'sku_name'=>$k,
                    'spec_num'=>$v['goods_num'],
                );
            }
        }
        $res_spec=0;
        $newSpec=array();
        for($i=0;$i<count($itemDataList);$i++){
            $itemDataList[$i]['spec_src']=tomedia($spec_src[$i]);
            $itemDataList[$i]['goods_id']=$goods_id;
            $itemDataList[$i]['uniacid']=$uniacid;
            //判断该规格是否已存在
            $isSpec=pdo_get('cqkundian_farm_integral_goods_spec',array('goods_id'=>$goods_id,'sku_name'=>$itemDataList[$i]['sku_name'],'uniacid'=>$uniacid));
            if($isSpec){
                $res_spec+=pdo_update('cqkundian_farm_integral_goods_spec',$itemDataList[$i],array('sku_name'=>$itemDataList[$i]['sku_name'],'goods_id'=>$goods_id,'uniacid'=>$uniacid));
            }else{
                $res_spec+=pdo_insert('cqkundian_farm_integral_goods_spec',$itemDataList[$i]);  //插入商品规格
            }
            $newSpecItem=pdo_get('cqkundian_farm_integral_goods_spec',array('sku_name'=>$itemDataList[$i]['sku_name'],'goods_id'=>$goods_id,'uniacid'=>$uniacid),array('sku_name'));
            $newSpec[]=$newSpecItem['sku_name'];
        }
        $oldSpecItem=pdo_getall('cqkundian_farm_integral_goods_spec',array('goods_id'=>$goods_id,'uniacid'=>$uniacid),array('sku_name'));
        $oldSpec=array();
        for($i=0;$i<count($oldSpecItem);$i++){
            $oldSpec[]=$oldSpecItem[$i]['sku_name'];
        }
        $oldSpecId=array();
        $oldSpecId = array_diff($oldSpec, $newSpec);
        if(!empty($oldSpecId)){
            //删除原来的规格值
            for($i=0;$i<count($oldSpecId);$i++){
                $del_old=pdo_delete('cqkundian_farm_integral_goods_spec',array('sku_name'=>$oldSpecId[$i],'uniacid'=>$uniacid,'goods_id'=>$goods_id));
            }
        }

        //修改规格项的goods_id
        $res_spec_item=0;
        for($i=0;$i<count($specItem);$i++){
            $res_spec_item+=pdo_update('cqkundian_farm_integral_spec',array('goods_id'=>$goods_id),array('id'=>$specItem[$i],'uniacid'=>$uniacid));
        }
        if($goods_update_res || $res_spec || $res_spec_item){
            message("修改成功",$url);
        }else{
            message("没有修改任何信息");
        }
    }else{      //关闭
        //删除原来的规格信息
        $del_res=pdo_delete('cqkundian_farm_integral_goods_spec',array('goods_id'=>$goods_id,'uniacid'=>$uniacid));
        //删除该商品的规格项以及规格值
        $delSpecItem=pdo_getall('cqkundian_farm_integral_spec',array('uniacid'=>$uniacid,'goods_id'=>$goods_id));
        for($i=0;$i<count($delSpecItem);$i++){
            pdo_delete('cqkundian_farm_integral_spec_value',array('spec_id'=>$delSpecItem[$i]['id'],'uniacid'=>$uniacid));
        }
        pdo_delete('cqkundian_farm_integral_spec',array('uniacid'=>$uniacid,'goods_id'=>$goods_id));
        if($goods_update_res || $del_res){
            message('修改成功!',$url);
        }else{
            message('没有修改任何信息!');
        }
    }
    die;
}

//修改商品上架状态
if($op=='is_put_away_change'){
    $id=$_GPC['id'];
    $res=pdo_update('cqkundian_farm_integral_goods',array('is_put_away'=>$_GPC['status']),array('uniacid'=>$uniacid,'id'=>$id));
    echo $res ? json_encode(array('status'=>1)) : json_encode(array('status'=>2));die;
}

//修改商品的推荐状态
if($op=='is_recommendChange'){
    $id=$_GPC['id'];
    $res=pdo_update('cqkundian_farm_integral_goods',array('is_recommend'=>$_GPC['status']),array('uniacid'=>$uniacid,'id'=>$id));
    echo $res ? json_encode(array('status'=>1)) : json_encode(array('status'=>2));die;
}

//删除商品信息
if($op=='delete'){
    $goods_id=$_GPC['id'];
    $res=pdo_delete('cqkundian_farm_integral_goods',array('id'=>$goods_id,'uniacid'=>$uniacid));
    if($res){
        //删除原来的规格信息
        $del_res=pdo_delete('cqkundian_farm_integral_goods_spec',array('goods_id'=>$goods_id,'uniacid'=>$uniacid));
        //删除该商品的规格项以及规格值
        $delSpecItem=pdo_getall('cqkundian_farm_integral_spec',array('uniacid'=>$uniacid,'goods_id'=>$goods_id));
        for($i=0;$i<count($delSpecItem);$i++){
            pdo_delete('cqkundian_farm_integral_spec_value',array('spec_id'=>$delSpecItem[$i]['id'],'uniacid'=>$uniacid));
        }
        pdo_delete('cqkundian_farm_integral_spec',array('uniacid'=>$uniacid,'goods_id'=>$goods_id));
        echo json_encode(array('status'=>1));
    }else{
        echo json_encode(array('status'=>2));die;
    }

}

//批量删除商品信息
if($op=='batch_delete'){
    $goods_ids=$_GPC['goodsid'];
    $res=0;
    for ($i=0;$i<count($goods_ids);$i++){
        $res+=pdo_delete('cqkundian_farm_integral_goods',array('id'=>$goods_ids[$i],'uniacid'=>$uniacid));
        if($res){
            //删除原来的规格信息
            $del_res=pdo_delete('cqkundian_farm_integral_goods_spec',array('goods_id'=>$goods_ids[$i],'uniacid'=>$uniacid));
            //删除该商品的规格项以及规格值
            $delSpecItem=pdo_getall('cqkundian_farm_integral_spec',array('uniacid'=>$uniacid,'goods_id'=>$goods_ids[$i]));
            for($j=0;$j<count($delSpecItem);$j++){
                pdo_delete('cqkundian_farm_integral_spec_value',array('spec_id'=>$delSpecItem[$j]['id'],'uniacid'=>$uniacid));
            }
            pdo_delete('cqkundian_farm_integral_spec',array('uniacid'=>$uniacid,'goods_id'=>$goods_ids[$i]));
        }
    }
    $url=url('site/entry/integralShop', array('m' => 'kundian_farm','op'=>'integral_shop'));
    if($res){
        message('删除成功',$url);
    }else{
        message('操作失败');
    }
}

//添加规格组
if($op=='addSkuItem'){
    $name=$_GPC['sku_name'];
    $res=pdo_insert('cqkundian_farm_integral_spec',array('name'=>$name,'uniacid'=>$uniacid));
    $spec_id=pdo_insertid();
    echo $res ? json_encode(array('code'=>1,'spec_id'=>$spec_id)) : json_encode(array('code'=>2));die;
}

//删除规格项
if($op=='deleteSkuItem'){
    $id=$_GPC['id'];
    $spec_id_str=explode('_', $_GPC['spec_id_str']);
    $returnStr=getSpecSku($spec_id_str,$uniacid);
    $returnStr['code']=1;
    $res=pdo_delete('cqkundian_farm_integral_spec',array('uniacid'=>$uniacid,'id'=>$id));
    echo $res ? json_encode($returnStr) : json_encode(array('code'=>2));die;
}

//添加规格值
if($op=='addSkuVal'){
    $is_type=$_GPC['is_type'];
    $spec_id=$_GPC['specid'];
    $value=$_GPC['spec_value'];
    $spec_id_str=explode('_', $_GPC['spec_id_str']);
    $insertData=array(
        'uniacid'=>$uniacid,
        'spec_id'=>$spec_id,
        'spec_value'=>$value,
    );
    $res=pdo_insert('cqkundian_farm_integral_spec_value',$insertData);  //插入数据
    $spec_val_id=pdo_insertid();
    $returnStr=getSpecSku($spec_id_str,$uniacid);
    if(!empty($_GPC['is_type'])){  //编辑
        $goods_id=$_GPC['goods_id'];
        $newSkuSpec=$returnStr['newSkuSpec'];
        $goodsSpecVal=array();
        for($j=1;$j<=count($newSkuSpec);$j++){
            $goodsSpecVal[$j-1]=pdo_get('cqkundian_farm_integral_goods_spec',array('sku_name'=>$newSkuSpec[$j],'goods_id'=>$goods_id,'uniacid'=>$uniacid));
        }
    }
    $returnStr['goodsSpecVal']=$goodsSpecVal;
    $returnStr['spec_val_id']=$spec_val_id;
    $returnStr['code']=1;
    echo json_encode($returnStr);die;
}

//删除规格值
if($op=='deleteSkuVal'){
    $spec_id=$_GPC['spec_id'];
    $spec_val_id=$_GPC['spec_val_id'];
    $spec_id_str=explode('_', $_GPC['spec_id_str']);  //当前规格项
    $res=pdo_delete("cqkundian_farm_integral_spec_value",array('spec_id'=>$spec_id,'id'=>$spec_val_id,'uniacid'=>$uniacid));
    $returnStr=getSpecSku($spec_id_str,$uniacid);
    if(!empty($_GPC['is_type'])){  //编辑
        $goods_id=$_GPC['goods_id'];
        $specValue=pdo_getall('cqkundian_farm_integral_goods_spec',array('goods_id'=>$goods_id,'uniacid'=>$uniacid));//获取该商品的所有规格值
        $newSkuSpec=$returnStr['newSkuSpec'];
        $goodsSpecVal=array();
        for($j=1;$j<=count($newSkuSpec);$j++){
            $goodsSpecVal[$j-1]=pdo_get('cqkundian_farm_integral_goods_spec',array('sku_name'=>$newSkuSpec[$j],'goods_id'=>$goods_id,'uniacid'=>$uniacid));
        }
        $delete_where['sku_name LIKE']="%".$spec_val_id.'%';
        $delete_where['goods_id']=$goods_id;
        $delete_where['uniacid']=$uniacid;
        pdo_delete('cqkundian_farm_integral_goods_spec',$delete_where);
        $returnStr['goodsSpecVal']=$goodsSpecVal;
    }
    echo  $res ?json_encode($returnStr) : json_encode(array('code'=>2));die;
}

//添加商品分类
if($op=='integral_goods_type'){
    $condition=array();
    if(!empty($_GPC['type_name'])){
        $type_name=trim($_GPC['type_name']);
        $condition['type_name LIKE']='%'.$type_name.'%';
    }
    $condition['uniacid']=$uniacid;
    $allData=pdo_getall('cqkundian_farm_integral_goods_type',$condition);
    $listCount=count($allData);
    $pageSize=10;       //每页显示数据条数
    $pageIndex=$_GPC['page'] ? intval($_GPC['page']) :1;    //当前页面
    $pager=pagination($listCount,$pageIndex,$pageSize);
    $list=pdo_getall('cqkundian_farm_integral_goods_type',$condition,'','','rank asc',array($pageIndex,$pageSize));
    include $this->template("web/integralShop/goods_type_list");
}

//编辑添加商品分类
if($op=='goods_type_edit'){
    if(!empty($_GPC['id'])){
        $list=pdo_get('cqkundian_farm_integral_goods_type',array('id'=>$_GPC['id'],'uniacid'=>$uniacid));
    }
    include $this->template("web/integralShop/goods_type_edit");
}

//保存商品分类信息
if($op=='goods_type_save'){
    $insertData=array(
        'type_name'=>trim($_GPC['type_name']),
        'rank'=>trim($_GPC['rank']),
        'icon'=>trim(tomedia($_GPC['icon'])),
        'status'=>trim($_GPC['status']),
        'uniacid'=>$uniacid,
    );
    if(empty($_GPC['id'])){
        $insertData['create_time']=time();
        $res=pdo_insert("cqkundian_farm_integral_goods_type",$insertData);
    }else{
        $res=pdo_update("cqkundian_farm_integral_goods_type",$insertData,array('id'=>$_GPC['id'],'uniacid'=>$uniacid));
    }
    $url=url('site/entry/integralShop', array('m' => 'kundian_farm','op'=>'integral_goods_type'));
    $res ? message("操作成功",$url ): message("操作失败");die;
}

//改变商品分类的状态
if($op=='change_goods_type_status'){
    $id=$_GPC['id'];
    $status=$_GPC['status'];
    $res=pdo_update('cqkundian_farm_integral_goods_type',array('status'=>$status),array('id'=>$id,'uniacid'=>$uniacid));
    echo $res ? json_encode(array('status'=>1)) : json_encode(array('status'=>2));die;
}

if($op=='change_is_show_integral'){
    $id=$_GPC['id'];
    $status=$_GPC['status'];
    $res=pdo_update('cqkundian_farm_integral_goods_type',array('is_show_integral'=>$status),array('id'=>$id,'uniacid'=>$uniacid));
    echo $res ? json_encode(array('status'=>1)) : json_encode(array('status'=>2));die;
}

//删除商品分类信息
if($op=='goods_type_delete'){
    $id=$_GPC['id'];
    $res=pdo_delete('cqkundian_farm_integral_goods_type',array('id'=>$id,'uniacid'=>$uniacid));
    echo $res ? json_encode(array('status'=>1)) : json_encode(array('status'=>2));die;
}

/**
 * 获取规格的组合值，当前选中的规格项，规格值对应的详细信息
 * @param  [array] $spec_id [规格项id]
 * @param  [int] $uniacid [当前小程序id]
 * @return [array]          [array]
 */
function getSpecSku($spec_id,$uniacid){
    sort($spec_id);  //将数组排序
    $returnStr=array();
    $specItem=pdo_getall("cqkundian_farm_integral_spec",array('id in'=>$spec_id,'uniacid'=>$uniacid));
    $arr=array();
    for($i=0;$i<count($specItem);$i++) {
        $spec_where['spec_id'] = $specItem[$i]['id'];  //所有的规格项
        $spec_where['uniacid']=$uniacid;
        $specValue = pdo_getall('cqkundian_farm_integral_spec_value', $spec_where, 'id');
        for ($j = 0; $j < count($specValue); $j++) {
            $arr[$specItem[$i]['id']][] = $specValue[$j]['id'];
        }
    }
    //得到组合后的SKU数组
    $newSpec=ok($arr);
    $skuSpec=array();
    for($i=1;$i<count($newSpec)+1;$i++){
        $new_spec_arr=explode(",",$newSpec[$i]);
        $skuSpec[$i-1]=pdo_getall('cqkundian_farm_integral_spec_value',array('id in'=>$new_spec_arr,'uniacid'=>$uniacid));
    }

    $returnStr['specItem']=$specItem;
    $returnStr['newSkuSpec']=$newSpec;
    $returnStr['skuSpec']=$skuSpec;
    return $returnStr;
}
/**
 *  要解决的数学问题    ：算出C(a,1) * C(b, 1) * ... * C(n, 1)的组合情况，其中C(n, 1)代表从n个元素里任意取一个元素
 *  要解决的实际问题样例：某年级有m个班级，每个班的人数不同，现在要从每个班里抽选一个人组成一个小组，
 *  由该小组来代表该年级参加学校的某次活动，请给出所有可能的组合
 *
 *  需要进行排列组合的数组
 *  数组说明：该数组是一个二维数组，第一维索引代表班级编号，第二维索引代表学生编号
 *  $CombinList = array(1 => array("Student10", "Student11"),
 *                      2 => array("Student20", "Student21", "Student22"),
 *                      3 => array("Student30"),
 *                      4 => array("Student40", "Student41", "Student42", "Student43"));
 *
 *  计算C(a,1) * C(b, 1) * ... * C(n, 1)的值
 *
 *
 * @param  [array] $CombinList [description]
 * @return [type]             [description]
 */
function ok($CombinList) {
    $CombineCount = 1;
    foreach ($CombinList as $Key => $Value) {
        $CombineCount *= count($Value);
    }
    $RepeatTime = $CombineCount;
    foreach ($CombinList as $ClassNo => $StudentList) {
        // $StudentList中的元素在拆分成组合后纵向出现的最大重复次数
        $RepeatTime = $RepeatTime / count($StudentList);
        $StartPosition = 1;
        // 开始对每个班级的学生进行循环
        foreach ($StudentList as $Student) {
            $TempStartPosition = $StartPosition;
            $SpaceCount = $CombineCount / count($StudentList) / $RepeatTime;
            for ($J = 1; $J <= $SpaceCount; $J ++) {
                for ($I = 0; $I < $RepeatTime; $I ++) {
                    $Result[$TempStartPosition + $I][$ClassNo] = $Student;
                }
                $TempStartPosition += $RepeatTime * count($StudentList);
            }
            $StartPosition += $RepeatTime;
        }
    }
    if($Result){
        foreach ($Result as $k => $v) {
            $Result[$k] = implode(',', $v);
        }   
    }
    return $Result;
}